﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace JewererBasic.BO
{
    public class KindBO
    {
        static MSQDBEntities db = new MSQDBEntities();
        
        public static bool Update(int id, string name)
        {
            KIND kind = db.KINDs.Find(id);
            if (kind == null || String.IsNullOrEmpty(name))
                return false;
            kind.Name = name;
            db.SaveChanges();
            return true;
        }

        public static List<KIND> Kinds()
        {
            return db.KINDs.ToList();
        }

        public static int GetId(string name)
        {
            var query = (from d in db.KINDs
                         where d.Name.Equals(name)
                         select d).ToList();
            if (query.Count == 1)
                return query.First().Id;
            throw new NullReferenceException("Can't find Kind: " + name);
        }
    }
}